

namespace Stee.CAP8.MessageBus.Interface.Interfaces
{
    using System;
    using Stee.CAP8.MessageBus.Interface.Delegates;
    using Stee.CAP8.MessageBus.Interface.Models;

    /// <summary>
    /// Interface for message bus factory to initialize broker deployment
    /// </summary>
    /// <typeparam name="TConfig">User defined for specific broker type configuration (Kafka, Redis, Pulsar, RabbitMQ, etc.)</typeparam>
    public interface IMessageBusFactory<TConfig> : IDisposable
    {
        /// <summary>
        /// Gets the flag indicating if message bus is initialized
        /// </summary>
        bool IsInitialized { get; }


        /// <summary>
        /// Initialize the message bus factory
        /// </summary>
        /// <param name="username">Username, nullable</param>
        /// <param name="password">Password, nullable</param>
        /// <param name="brokerConfigurations">Broker configurations: topic list, groups, other detailed settings, nullable</param>
        void Initialize(string username, string password, TConfig brokerConfigurations);


        /// <summary>
        /// Register/create new publisher
        /// </summary>
        /// <typeparam name="TMessage">Message data type</typeparam>
        /// <param name="topicName">Message topic</param>
        /// <param name="clientID"></param>
        /// <param name="publishResponseHandler">Handler for published topic message</param>
        /// <param name="publisherErrorHandler"></param>
        /// <returns>Return new publisher</returns>
        IDisposable CreatePublisher<TMessage>(TopicName topicName, string clientID,
            HandlePublishResponse<TMessage> publishResponseHandler, HandleBrokerError publisherErrorHandler);

        /// <summary>
        /// Register/create new subscriber
        /// </summary>
        /// <typeparam name="TMessage">Message data type</typeparam>
        /// <param name="topicName">Topic name</param>
        /// <param name="groupID"></param>
        /// <param name="clientID"></param>
        /// <param name="subscribeTopicHandler">Handler for subscribed topic message</param>
        /// <param name="brokerErrorHandler"></param>
        /// <returns>Return new subscriber</returns>
        IDisposable CreateSubscriber<TMessage>(TopicName topicName, string groupID, string clientID,
            HandleSubscribeTopic<TMessage> subscribeTopicHandler, HandleBrokerError brokerErrorHandler);
    }
}
